package com.wangsd.web.face.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.MyController;
import com.wangsd.web.face.entity.Member;
import com.wangsd.web.face.service.MemberService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-10-23
 */
@Api(value = "member", tags = "会员管理")
@RestController
@RequestMapping("/face/member")
@Slf4j
public class MemberController extends MyController {
    @Autowired
    MemberService memberService;

    @ApiOperation(value = "查询会员列表", notes = "查询会员列表", httpMethod = "POST")
    @RequestMapping(value = "/selectList/{pageNum}/{pageSize}", method = RequestMethod.POST)
    public Result<IPage<Member>> selectList(@ApiParam(value = "当前页", required = true) @PathVariable("pageNum") Integer pageNum,
                                           @ApiParam(value = "每页大小", required = true) @PathVariable("pageSize") Integer pageSize,
                                           @RequestBody @ApiParam(name = "params", value = "传入json格式") Member params) {
        SysUser loginUser = getUserInfo();
        IPage<Member> resultIPage = memberService.selectList(pageNum, pageSize, params, loginUser.getCode());
        return Result.success(resultIPage);
    }


    @ApiOperation(value = "新增或修改会员", notes = "新增或修改会员", httpMethod = "POST", response = Result.class)
    @RequestMapping(value = "addOrUpdate", method = RequestMethod.POST)
    public Result addOrUpdate(Member params) {
        memberService.addOrUpdate(params);
        return Result.success();
    }

    @ApiOperation(value = "删除会员信息", notes = "删除会员信息", httpMethod = "GET", response = Result.class)
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Result delete(@ApiParam(value = "用户id", required = true) @PathVariable("id") Long id) {
        memberService.removeById(id);
        return Result.success();
    }

    @ApiOperation(value = "通过id查询会员", notes = "通过id查询会员", httpMethod = "GET", response = Result.class)
    @GetMapping("/selectById/{id}")
    public Result<Member> selectById(@ApiParam(value = "服务商id", required = true) @PathVariable Long id) {
        Member result = memberService.getById(id);
        return Result.success(result);
    }
}

